--- src/main.c	2005/11/04 11:02:27	1.1
+++ src/main.c	2005/11/04 11:16:28
@@ -1695,7 +1695,7 @@ name             width\theight\tllx\tlly
 	}
 
       /* Table of Contents. */
-      if (toc)
+      if (ofp != NULL && toc)
 	{
 	  /* This is really cool... */
 
@@ -1714,9 +1714,11 @@ name             width\theight\tllx\tlly
 	      process_file (_("Table of Contents"), &is, 1);
 	      is_close (&is);
 	    }
-
-	  /* Clean up toc file. */
-	  fclose (toc_fp);
+	  else
+	    {
+	      /* Clean up toc file. */
+	      fclose (toc_fp);
+	    }
 	}
 
       /* Give trailer a chance to dump itself. */
